package com.example.opengldemo;

import androidx.appcompat.app.AppCompatActivity;

import android.content.pm.ActivityInfo;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.SeekBar;

import com.example.opengldemo._01_.MyTDView;
import com.example.opengldemo._026_._026_MySurfaceView;
import com.example.opengldemo._05_.MySurfaceView;
import com.example.opengldemo._06_._6MySurfaceView;
import com.example.opengldemo._07_texture._07_MyTextureSurfaceView;
import com.example.opengldemo.util.MatrixState;

public class MainActivity extends AppCompatActivity {
    MyTDView mview;
    MySurfaceView mySurfaceView;
    _6MySurfaceView _6mySurfaceView;
    _026_MySurfaceView mySurfaceView_026_ ;
    _07_MyTextureSurfaceView myTextureSurfaceView_07_ ;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main); //跳转到相关界面
        LinearLayout ll = (LinearLayout) findViewById(R.id.main_liner);
        ll.addView(initTDView());
        SeekBar sb = findViewById(R.id.SeekBar01);
        sb.setOnSeekBarChangeListener(
                new SeekBar.OnSeekBarChangeListener() {
                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress,
                                                  boolean fromUser) {
                        float lightOffset = (seekBar.getMax() / 2.0f - progress) / (seekBar.getMax() / 2.0f) * -4 ;
                        MatrixState.setLightLocation(lightOffset, 0, 1.5f); //设置光源位置

                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }
                }
        );

        SeekBar sb2 = findViewById(R.id.SeekBar02);
        sb2.setOnSeekBarChangeListener(
                new SeekBar.OnSeekBarChangeListener() {
                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress,
                                                  boolean fromUser) {
                        float cameraOffset = (seekBar.getMax() / 2.0f - progress) / (seekBar.getMax() / 2.0f) * -4 ;
                        MatrixState.setCamera(cameraOffset, 0, 2f, 0, 0, 0f, 0f, 1.0f, 0.0f
                        ); //设置光源位置
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                    }
                }
        );
    }

    public GLSurfaceView initTDView() {
        mview = new MyTDView(this); //创建 MyTDView 类的对象
        mview.requestFocus(); //获取焦点
        mview.setFocusableInTouchMode(true); //设置为可触控
        return mview;
    }

    public GLSurfaceView initMySurView() {
        mySurfaceView = new MySurfaceView(this); //创建 MyTDView 类的对象
        mySurfaceView.requestFocus(); //获取焦点
        mySurfaceView.setFocusableInTouchMode(true); //设置为可触控
        return mySurfaceView;
    }

    public GLSurfaceView init_06MySurView() {
        _6mySurfaceView = new _6MySurfaceView(this); //创建 MyTDView 类的对象
        _6mySurfaceView.requestFocus(); //获取焦点
        _6mySurfaceView.setFocusableInTouchMode(true); //设置为可触控
        return _6mySurfaceView;
    }

    public GLSurfaceView init_026_MySurView() {
        mySurfaceView_026_ = new _026_MySurfaceView(this); //创建 MyTDView 类的对象
        mySurfaceView_026_.requestFocus(); //获取焦点
        mySurfaceView_026_.setFocusableInTouchMode(true); //设置为可触控
        return mySurfaceView_026_;
    }

    public GLSurfaceView init_07_MySurView() {
        myTextureSurfaceView_07_ = new _07_MyTextureSurfaceView(this); //创建 MyTDView 类的对象
        myTextureSurfaceView_07_.requestFocus(); //获取焦点
        myTextureSurfaceView_07_.setFocusableInTouchMode(true); //设置为可触控
        return myTextureSurfaceView_07_;
    }


    @Override
    public void onResume() {
        super.onResume();

        if(myTextureSurfaceView_07_ != null)myTextureSurfaceView_07_.onResume();
        if(mview != null)mview.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        if(myTextureSurfaceView_07_ != null)myTextureSurfaceView_07_.onPause();
        if(mview != null)mview.onPause();

    }
}
